#include<string>
#include<vector>
#include<sstream>
#include<iostream>
class Solution {
public:
    int index = 0;
    int len = 0;
    std::string str = "";
    std::string decodeString(std::string s) {
         len = static_cast<int>(s.length());
        str = s;
        std::stringstream ss;
        while (index<len)
        {
            if (str[index]<='9'&&str[index]>='0')
            {
                ss<<f();
            }else
            {
                ss<<str[index];
            }
            index++;
        }
        return ss.str();
    }

    std::string f()
    {
        std::stringstream s ;
       int num = findNoNum();
        while (index<len&&str[index]!=']')
        {
            if (str[index]<='9'&&str[index]>='0')
            {
                s<<f();
            }else
            {
                s<<str[index];
            }
            index++;
        }
        std::string a = s.str();
        for (int i=0;i<num-1;i++)
        {
            s<<a;
        }
        return s.str();
    }
    int findNoNum()
    {
      
        std::stringstream s ;
  
        while (index<len)
        {
          
            if (str[index]<='9'&&str[index]>='0')
            {
                s<<str[index];
               
            }else
            {
                break;
            }
            index++;
        }
        index++;
        return std::stoi(s.str());
    }
    
};
